﻿﻿namespace NFinal
{
    public class ActionSearch
    {
        public static int Search(string requestedPath)
        {
			//重写虚拟目录
			//重写虚拟路径,也可以把此部分放到find中
			switch (requestedPath)
			{
				//网站图标
				case "/favicon.ico": return 0;
				case "/App/Index.html":requestedPath = "/App/IndexController/Index.html"; break;
				default: break;
			}
            //获取actionUrl
            string actionUrl = GetActionUrl(requestedPath);
            int find = GetActionId(actionUrl, requestedPath);
            return find;
        }
        /// <summary>
        /// 计算actionUrl
        /// </summary>
        /// <param name="requestedPath"></param>
        /// <returns></returns>
        private static string GetActionUrl(string requestedPath)
        {
            //找到最后一个.的位置
            int position = requestedPath.LastIndexOf('.');
            bool hasExtension = false;
            //判断是否有后缀（后缀首字母不能为数字，且长度必须大于0小于5）
            int extesionLength = requestedPath.Length - position-1;
            if (extesionLength > 0 && extesionLength < 5)
            {
                char ch = requestedPath[position + 1];
				//.后面不是数字
                if (ch > '9' || ch < '0')
                {
					hasExtension = true;
                }
            }
            //指向ActionUrl结尾的位置
            int pointer = 0;
            string actionUrl = requestedPath;
            bool hasGet = false;
            //如果有后缀
            if (hasExtension)
            {
                hasGet = int.TryParse(requestedPath.Substring(position - 2, 2), out pointer);
            }
            //如果没有后缀
            else
            {
                hasGet = int.TryParse(requestedPath.Substring(requestedPath.Length - 2, 2), out pointer);
            }
            //取出ActionUrl
            if (hasGet)
            {
                if (pointer > -1 && pointer < requestedPath.Length)
                {
                    actionUrl = requestedPath.Substring(0, pointer + 1);
                }
            }
            return actionUrl;
        }
        /// <summary>
        /// 查询actionUrl
        /// </summary>
        /// <param name="app"></param>
        /// <param name="actionUrl"></param>
        /// <param name="requestedPath"></param>
        /// <returns></returns>
        private static int GetActionId(string actionUrl, string requestedPath)
        {
            int find = 0;
            //无参数
            switch (requestedPath)
            {
				case "/App/IndexController/Index.html":
                    find = 1; break;
				case "/App/mysql/queryAll.html":
                    find = 6; break;
				case "/App/mysql/queryObject.html":
                    find = 7; break;
				case "/App/mysql/queryRandom.html":
                    find = 8; break;
				case "/App/mysqlStruct/queryAll.html":
                    find = 15; break;
				case "/App/mysqlStruct/queryObject.html":
                    find = 16; break;
				case "/App/mysqlStruct/queryRandom.html":
                    find = 17; break;
				case "/App/mysqlTrans/queryAll.html":
                    find = 24; break;
				case "/App/mysqlTrans/queryObject.html":
                    find = 25; break;
				case "/App/mysqlTrans/queryRandom.html":
                    find = 26; break;
				case "/App/oracle/queryAll.html":
                    find = 33; break;
				case "/App/oracle/queryObject.html":
                    find = 34; break;
				case "/App/oracle/queryRandom.html":
                    find = 35; break;
				case "/App/oracleStruct/queryAll.html":
                    find = 42; break;
				case "/App/oracleStruct/queryObject.html":
                    find = 43; break;
				case "/App/oracleStruct/queryRandom.html":
                    find = 44; break;
				case "/App/oracleTrans/queryAll.html":
                    find = 51; break;
				case "/App/oracleTrans/queryObject.html":
                    find = 52; break;
				case "/App/oracleTrans/queryRandom.html":
                    find = 53; break;
				case "/App/postgresql/queryAll.html":
                    find = 60; break;
				case "/App/postgresql/queryObject.html":
                    find = 61; break;
				case "/App/postgresql/queryRandom.html":
                    find = 62; break;
				case "/App/postgresqlStruct/queryAll.html":
                    find = 69; break;
				case "/App/postgresqlStruct/queryObject.html":
                    find = 70; break;
				case "/App/postgresqlStruct/queryRandom.html":
                    find = 71; break;
				case "/App/postgresqlTrans/queryAll.html":
                    find = 78; break;
				case "/App/postgresqlTrans/queryObject.html":
                    find = 79; break;
				case "/App/postgresqlTrans/queryRandom.html":
                    find = 80; break;
				case "/App/Sqlite/queryAll.html":
                    find = 87; break;
				case "/App/Sqlite/queryObject.html":
                    find = 88; break;
				case "/App/Sqlite/queryRandom.html":
                    find = 89; break;
				case "/App/SqliteBLL/queryAll.html":
                    find = 92; break;
				case "/App/SqliteBLL/queryRandom.html":
                    find = 93; break;
				case "/App/SqliteStruct/queryAll.html":
                    find = 98; break;
				case "/App/SqliteStruct/queryObject.html":
                    find = 99; break;
				case "/App/SqliteStruct/queryRandom.html":
                    find = 100; break;
				case "/App/SqliteTrans/queryAll.html":
                    find = 107; break;
				case "/App/SqliteTrans/queryObject.html":
                    find = 108; break;
				case "/App/SqliteTrans/queryRandom.html":
                    find = 109; break;
				case "/App/SqliteTransStruct/queryAll.html":
                    find = 116; break;
				case "/App/SqliteTransStruct/queryObject.html":
                    find = 117; break;
				case "/App/SqliteTransStruct/queryRandom.html":
                    find = 118; break;
				case "/App/SqlServer/queryAll.html":
                    find = 125; break;
				case "/App/SqlServer/queryObject.html":
                    find = 126; break;
				case "/App/SqlServer/queryRandom.html":
                    find = 127; break;
				case "/App/SqlServerStruct/queryAll.html":
                    find = 134; break;
				case "/App/SqlServerStruct/queryObject.html":
                    find = 135; break;
				case "/App/SqlServerStruct/queryRandom.html":
                    find = 136; break;
				case "/App/SqlServerTrans/queryAll.html":
                    find = 143; break;
				case "/App/SqlServerTrans/queryObject.html":
                    find = 144; break;
				case "/App/SqlServerTrans/queryRandom.html":
                    find = 145; break;
				case "/App/Public/Header.html":
                    find = 150; break;
				case "/App/Public/Footer.html":
                    find = 151; break;
				case "/App/Public/Navigator.html":
                    find = 152; break;
				case "/App/Public/KindEditor.html":
                    find = 153; break;
				case "/App/VCode/GetVerifyImage.html":
                    find = 154; break;
                default: find = 0; break;
            }
			//有参数
			if(find==0)
			{
				switch (actionUrl)
				{
					case "/App/mysql/update/":
						find = 2; break;
					case "/App/mysql/insert/":
						find = 3; break;
					case "/App/mysql/delete/":
						find = 4; break;
					case "/App/mysql/page/":
						find = 5; break;
					case "/App/mysql/queryRow/":
						find = 9; break;
					case "/App/mysql/queryTop/":
						find = 10; break;
					case "/App/mysqlStruct/update/":
						find = 11; break;
					case "/App/mysqlStruct/insert/":
						find = 12; break;
					case "/App/mysqlStruct/delete/":
						find = 13; break;
					case "/App/mysqlStruct/page/":
						find = 14; break;
					case "/App/mysqlStruct/queryRow/":
						find = 18; break;
					case "/App/mysqlStruct/queryTop/":
						find = 19; break;
					case "/App/mysqlTrans/update/":
						find = 20; break;
					case "/App/mysqlTrans/insert/":
						find = 21; break;
					case "/App/mysqlTrans/delete/":
						find = 22; break;
					case "/App/mysqlTrans/page/":
						find = 23; break;
					case "/App/mysqlTrans/queryRow/":
						find = 27; break;
					case "/App/mysqlTrans/queryTop/":
						find = 28; break;
					case "/App/oracle/update/":
						find = 29; break;
					case "/App/oracle/insert/":
						find = 30; break;
					case "/App/oracle/delete/":
						find = 31; break;
					case "/App/oracle/page/":
						find = 32; break;
					case "/App/oracle/queryRow/":
						find = 36; break;
					case "/App/oracle/queryTop/":
						find = 37; break;
					case "/App/oracleStruct/update/":
						find = 38; break;
					case "/App/oracleStruct/insert/":
						find = 39; break;
					case "/App/oracleStruct/delete/":
						find = 40; break;
					case "/App/oracleStruct/page/":
						find = 41; break;
					case "/App/oracleStruct/queryRow/":
						find = 45; break;
					case "/App/oracleStruct/queryTop/":
						find = 46; break;
					case "/App/oracleTrans/update/":
						find = 47; break;
					case "/App/oracleTrans/insert/":
						find = 48; break;
					case "/App/oracleTrans/delete/":
						find = 49; break;
					case "/App/oracleTrans/page/":
						find = 50; break;
					case "/App/oracleTrans/queryRow/":
						find = 54; break;
					case "/App/oracleTrans/queryTop/":
						find = 55; break;
					case "/App/postgresql/update/":
						find = 56; break;
					case "/App/postgresql/insert/":
						find = 57; break;
					case "/App/postgresql/delete/":
						find = 58; break;
					case "/App/postgresql/page/":
						find = 59; break;
					case "/App/postgresql/queryRow/":
						find = 63; break;
					case "/App/postgresql/queryTop/":
						find = 64; break;
					case "/App/postgresqlStruct/update/":
						find = 65; break;
					case "/App/postgresqlStruct/insert/":
						find = 66; break;
					case "/App/postgresqlStruct/delete/":
						find = 67; break;
					case "/App/postgresqlStruct/page/":
						find = 68; break;
					case "/App/postgresqlStruct/queryRow/":
						find = 72; break;
					case "/App/postgresqlStruct/queryTop/":
						find = 73; break;
					case "/App/postgresqlTrans/update/":
						find = 74; break;
					case "/App/postgresqlTrans/insert/":
						find = 75; break;
					case "/App/postgresqlTrans/delete/":
						find = 76; break;
					case "/App/postgresqlTrans/page/":
						find = 77; break;
					case "/App/postgresqlTrans/queryRow/":
						find = 81; break;
					case "/App/postgresqlTrans/queryTop/":
						find = 82; break;
					case "/App/Sqlite/update.html":
						find = 83; break;
					case "/App/Sqlite/insert/":
						find = 84; break;
					case "/App/Sqlite/delete/":
						find = 85; break;
					case "/App/Sqlite/page-":
						find = 86; break;
					case "/App/Sqlite/queryRow/":
						find = 90; break;
					case "/App/Sqlite/queryTop/":
						find = 91; break;
					case "/App/SqliteStruct/update/":
						find = 94; break;
					case "/App/SqliteStruct/insert/":
						find = 95; break;
					case "/App/SqliteStruct/delete/":
						find = 96; break;
					case "/App/SqliteStruct/page/":
						find = 97; break;
					case "/App/SqliteStruct/queryRow/":
						find = 101; break;
					case "/App/SqliteStruct/queryTop/":
						find = 102; break;
					case "/App/SqliteTrans/update/":
						find = 103; break;
					case "/App/SqliteTrans/insert/":
						find = 104; break;
					case "/App/SqliteTrans/delete/":
						find = 105; break;
					case "/App/SqliteTrans/page/":
						find = 106; break;
					case "/App/SqliteTrans/queryRow/":
						find = 110; break;
					case "/App/SqliteTrans/queryTop/":
						find = 111; break;
					case "/App/SqliteTransStruct/update/":
						find = 112; break;
					case "/App/SqliteTransStruct/insert/":
						find = 113; break;
					case "/App/SqliteTransStruct/delete/":
						find = 114; break;
					case "/App/SqliteTransStruct/page/":
						find = 115; break;
					case "/App/SqliteTransStruct/queryRow/":
						find = 119; break;
					case "/App/SqliteTransStruct/queryTop/":
						find = 120; break;
					case "/App/SqlServer/update/":
						find = 121; break;
					case "/App/SqlServer/insert/":
						find = 122; break;
					case "/App/SqlServer/delete/":
						find = 123; break;
					case "/App/SqlServer/page/":
						find = 124; break;
					case "/App/SqlServer/queryRow/":
						find = 128; break;
					case "/App/SqlServer/queryTop/":
						find = 129; break;
					case "/App/SqlServerStruct/update/":
						find = 130; break;
					case "/App/SqlServerStruct/insert/":
						find = 131; break;
					case "/App/SqlServerStruct/delete/":
						find = 132; break;
					case "/App/SqlServerStruct/page/":
						find = 133; break;
					case "/App/SqlServerStruct/queryRow/":
						find = 137; break;
					case "/App/SqlServerStruct/queryTop/":
						find = 138; break;
					case "/App/SqlServerTrans/update/":
						find = 139; break;
					case "/App/SqlServerTrans/insert/":
						find = 140; break;
					case "/App/SqlServerTrans/delete/":
						find = 141; break;
					case "/App/SqlServerTrans/page/":
						find = 142; break;
					case "/App/SqlServerTrans/queryRow/":
						find = 146; break;
					case "/App/SqlServerTrans/queryTop/":
						find = 147; break;
					case "/App/Public/Success/":
						find = 148; break;
					case "/App/Public/Error/":
						find = 149; break;
					case "/App/VCode/VCheck/":
						find = 155; break;
					default: find = 0; break;
				}
			}
            return find;
        }
    }
}